package labeler {
	import flare.display.RectSprite;
	import flare.display.TextSprite;
	import flare.util.Property;
	import flare.util.Shapes;
	import flare.vis.data.Data;
	import flare.vis.data.DataSprite;
	import flare.vis.operator.label.Labeler;
	
	import flash.text.TextFormat;

	public class PopularityLabeler extends Labeler {
		/** @private */
//		protected override var _access:Property = 
		public function PopularityLabeler(source:*=null, group:String=Data.NODES,
										  format:TextFormat=null, filter:*=null, policy:String=LAYER) {
//			_access = Property.$("props.popularity");
			
			super(source, group, format, filter, policy);
			this.access = 'props.popularity';
			trace('PopularityLabeler 20 >' + _access.name);
//			new Property
//			new TextFormat
		}


		/**
		 * Performs label creation and layout for the given data sprite.
		 * Subclasses should override this method to perform custom labeling.
		 * @param d the data sprite to process
		 */
		protected override function process(d:DataSprite):void {
//			new DataSprite;
//			new Shapes
			// var label:CircleSprite = getCircle(d, true);
			var label:TextSprite = getRect(d, true);
			trace(' PopularityLabeler >' + label);
			
			var o:Object, x:Number, y:Number, a:Number, v:Boolean;
			if (_policy == LAYER) {
				o = _t.$(d);
				if (o.shape == Shapes.BLOCK) {
					x = o.u + o.w/2;
					y = o.v + o.h/2;
				} else {
					x = o.x;
					y = o.y;
				}
				a = o.alpha;
				v = o.visible;
				o = _t.$(label);
				o.x = x + xOffset;
				o.y = y + yOffset;
				o.alpha = a;
				o.visible = v;
			} else {
				o = _t.$(label);
				o.x = xOffset;
				o.y = yOffset;
			}
			label.render();
			
		}
		protected function getRect(d:DataSprite, create:Boolean=false, visible:Boolean=true):TextSprite {
			var label:TextSprite = _access.getValue(d);
//			var size:Number = d.size * IconRenderer.DEFAULT_SIZE;
			var width:Number = 10;
			var height:Number = 1.5;
			trace(' PopularityLabeler 68>' + label + ' ' + create);
			if (!label && !create) {
				return null;
			} else if (!label) {
				label = new TextSprite();
//				new TextSprite;
				label.graphics.drawRect(-width, -height, 2*width, 2*height);
				label.graphics.beginFill(0x00ff00);
				var text:String = getLabelText(d);
				trace(' PopularityLabeler 77 >' + text);
				var ratio:Number = new Number(text);
				label.graphics.drawRect(-width, -height, 2*width*ratio, 2*height);
				label.graphics.endFill();
				// trace('207> ' + d.data.id + ' ' + p);
				label.visible = visible;
				_access.setValue(d, label);

				
				if (_policy == LAYER) {
					_labels.addChild(label);
					label.x = d.x + xOffset;
					label.y = d.y + yOffset;
				} else {
					d.addChild(label);
					label.mouseEnabled = false;
					label.mouseChildren = false;
					label.x = xOffset;
					label.y = yOffset;
				}
				
				// trace('IconLabeler 236 > ' + label.x + ' ' + d.x);
				// trace('IconLabeler 237 > ' + label.y + ' ' + d.y);
			}
			return label;
		}

//		protected function 
	}
}